//
//  OJComment.m
//  openJira
//
//  Created by Vincent Demay on 01/05/10.
//  Copyright 2010 Goojet. All rights reserved.
//

#import "OJComment.h"


@implementation OJComment

@synthesize updated, author, body,
			delegate;

- (void) dealloc {
	[updated release];
	[author release];
	[body release];
	[super dealloc];
}

- (void) addToIssue:(OJIssue*) issue {
	[[OJConnector getDefault] addComment:self toIssue:issue];
}

- (void) request:(XMLRPCRequest *)request onResponseSuccessfull:(XMLRPCResponse*) response{
	[delegate object:self isSent:NO];
}

- (void) request:(XMLRPCRequest *)request onResponseError:(XMLRPCResponse*) response{
	[delegate object:self isSent:YES];
}


@end


///////////////////////// OJISSUELIST //////////////////////

@implementation OJCommentList

@synthesize comments, delegate;

- (id) init {
	self = [super init];
	if (self != nil) {
	}
	return self;
}


- (void) getCommentsForIssue:(OJIssue*) issue {
	[[OJConnector getDefault] getComments:self forIssue:issue];
}


////////////////////////// MANAGE RESPONSES ///////////////////
- (void) request:(XMLRPCRequest *)request onResponseSuccessfull:(XMLRPCResponse*) response{
	id fromResponse = [response  object];
	[comments release];
	comments = [[NSMutableArray alloc] init];
	
	for (int i=0; i<[fromResponse count]; i++) {
		OJComment *comment = [[OJComment alloc] init];
		comment.author = [((NSDictionary*)[fromResponse objectAtIndex:i]) objectForKey:@"author"];
		comment.body = [((NSDictionary*)[fromResponse objectAtIndex:i]) objectForKey:@"body"];
		comment.updated = [((NSDictionary*)[fromResponse objectAtIndex:i]) objectForKey:@"updated"];
		[comments addObject:comment];
		[OJComment release];
	}
	
	[delegate object:self isReady:NO];
}

- (void) request:(XMLRPCRequest *)request onResponseError:(XMLRPCResponse*) response{
	[delegate object:self isReady:YES];
}

@end


